cmake_minimum_required(VERSION 3.14)
project(hpsocket)

set(CMAKE_CXX_STANDARD 17)

aux_source_directory(brotli-c/common BROTIL_COMMON_PATH)
aux_source_directory(brotli-c/dec BROTIL_DEC_PATH)
aux_source_directory(brotli-c/enc BROTIL_ENC_PATH)


add_library(brotli STATIC
        ${BROTIL_COMMON_PATH}
        ${BROTIL_DEC_PATH}
        ${BROTIL_ENC_PATH})
target_include_directories(brotli PRIVATE brotli-c/include)

find_package(OpenSSL REQUIRED)
find_package(ZLIB REQUIRED)
find_package(unofficial-iconv CONFIG REQUIRED)

add_definitions(-D_NEED_HTTP -D_SSL_SUPPORT -D_NEED_SSL)

aux_source_directory(src HPSOCKET_SOURCE_BASE_PATH)
aux_source_directory(src/common HPSOCKET_SOURCE_COMMON_PATH)
aux_source_directory(src/common/crypto HPSOCKET_SOURCE_COMMON_CRYPTO_PATH)
aux_source_directory(src/common/http HPSOCKET_SOURCE_COMMON_HTTP_PATH)
aux_source_directory(src/common/kcp HPSOCKET_SOURCE_COMMON_KCP_PATH)

add_library(hpsocket STATIC
        ${HPSOCKET_SOURCE_BASE_PATH}
        ${HPSOCKET_SOURCE_COMMON_PATH}
        ${HPSOCKET_SOURCE_COMMON_CRYPTO_PATH}
        ${HPSOCKET_SOURCE_COMMON_HTTP_PATH}
        ${HPSOCKET_SOURCE_COMMON_KCP_PATH})

target_include_directories(hpsocket PRIVATE brotli-c/include)
target_link_libraries(hpsocket PRIVATE OpenSSL::SSL
        OpenSSL::Crypto
        unofficial::iconv::libiconv
        unofficial::iconv::libcharset
        ZLIB::ZLIB
        brotli
        )

set(TEST_HELPER_CPP test/helper.cpp)
set(TEST_HELPER_H test/helper.h)

set(ARQ_SERVER test/server/test5.cpp)
set(ARQ_CLIENT test/client/test6.cpp)

set(TCP_SERVER test/server/test1.cpp)
set(TCP_CLIENT test/client/test1.cpp)
set(TCP_AGENT test/client/test3.cpp)

set(TCP_SERVER_PACK test/server/test2.cpp)
set(TCP_CLIENT_PACK test/client/test2.cpp)
set(TCP_AGENT_PACK test/client/test4.cpp)

set(TCP_SERVER_PULL test/server/test7.cpp)
set(TCP_CLIENT_PULL test/client/test9.cpp)
set(TCP_AGENT_PULL test/client/testA.cpp)

set(UDP_CLIENT test/client/test5.cpp)
set(UDP_SEVER test/server/test3.cpp)
set(UDP_CAST test/client/test7.cpp)

set(HTTP_SERVER_4C test/server/test6.cpp)
set(HTTP_SERVER test/server/test4.cpp)
set(HTTP_CLIENT test/client/test8.cpp)

set(UDP_NODE test/client/testB.cpp)


add_definitions(-D_USE_HP_LIB)

add_executable(test_tcp_agent_pull
        ${TEST_HELPER_CPP}
        ${TEST_HELPER_H}
        ${TCP_AGENT_PULL}
        )
target_link_libraries(test_tcp_agent_pull PRIVATE hpsocket)
target_include_directories(test_tcp_agent_pull PRIVATE test/include)

add_executable(test_tcp_client_pull
        ${TEST_HELPER_CPP}
        ${TEST_HELPER_H}
        ${TCP_CLIENT_PULL}
        )
target_link_libraries(test_tcp_client_pull hpsocket)
target_include_directories(test_tcp_client_pull PRIVATE test/include)

add_executable(test_tcp_server_pull
        ${TEST_HELPER_CPP}
        ${TEST_HELPER_H}
        ${TCP_SERVER_PULL}
        )
target_link_libraries(test_tcp_server_pull hpsocket)
target_include_directories(test_tcp_server_pull PRIVATE test/include)

add_executable(test_http_client
        ${TEST_HELPER_CPP}
        ${TEST_HELPER_H}
        ${HTTP_CLIENT}
        )
target_link_libraries(test_http_client hpsocket)
target_include_directories(test_http_client PRIVATE test/include)

add_executable(test_http_server
        ${TEST_HELPER_CPP}
        ${TEST_HELPER_H}
        ${HTTP_SERVER}
        )
target_link_libraries(test_http_server hpsocket)
target_include_directories(test_http_server PRIVATE test/include)

add_executable(test_udp_cast
        ${TEST_HELPER_CPP}
        ${TEST_HELPER_H}
        ${UDP_CAST}
        )
target_link_libraries(test_udp_cast hpsocket)
target_include_directories(test_udp_cast PRIVATE test/include)

add_executable(test_udp_client
        ${TEST_HELPER_CPP}
        ${TEST_HELPER_H}
        ${UDP_CLIENT}
        )
target_link_libraries(test_udp_client hpsocket)
target_include_directories(test_udp_client PRIVATE test/include)


add_executable(test_udp_server
        ${TEST_HELPER_CPP}
        ${TEST_HELPER_H}
        ${UDP_SEVER}
        )
target_link_libraries(test_udp_server hpsocket)
target_include_directories(test_udp_server PRIVATE test/include)


add_executable(test_tcp_server_pack
        ${TEST_HELPER_CPP}
        ${TEST_HELPER_H}
        ${TCP_SERVER_PACK}
        )
target_link_libraries(test_tcp_server_pack hpsocket)
target_include_directories(test_tcp_server_pack PRIVATE test/include)

add_executable(test_tcp_client_pack
        ${TEST_HELPER_CPP}
        ${TEST_HELPER_H}
        ${TCP_CLIENT_PACK}
        )
target_link_libraries(test_tcp_client_pack hpsocket)
target_include_directories(test_tcp_client_pack PRIVATE test/include)

add_executable(test_tcp_agent_pack
        ${TEST_HELPER_CPP}
        ${TEST_HELPER_H}
        ${TCP_AGENT_PACK}
        )
target_link_libraries(test_tcp_agent_pack hpsocket)
target_include_directories(test_tcp_agent_pack PRIVATE test/include)

add_executable(test_tcp_server
        ${TEST_HELPER_CPP}
        ${TEST_HELPER_H}
        ${TCP_SERVER}
        )
target_link_libraries(test_tcp_server hpsocket)
target_include_directories(test_tcp_server PRIVATE test/include)

add_executable(test_tcp_client
        ${TEST_HELPER_CPP}
        ${TEST_HELPER_H}
        ${TCP_CLIENT}
        )
target_link_libraries(test_tcp_client hpsocket)
target_include_directories(test_tcp_client PRIVATE test/include)

add_executable(test_tcp_agent
        ${TEST_HELPER_CPP}
        ${TEST_HELPER_H}
        ${TCP_AGENT}
        )
target_link_libraries(test_tcp_agent hpsocket)
target_include_directories(test_tcp_agent PRIVATE test/include)

add_executable(test_arq_server
        ${TEST_HELPER_CPP}
        ${TEST_HELPER_H}
        ${ARQ_SERVER}
        )
target_link_libraries(test_arq_server hpsocket)
target_include_directories(test_arq_server PRIVATE test/include)

add_executable(test_arq_client
        ${TEST_HELPER_CPP}
        ${TEST_HELPER_H}
        ${ARQ_CLIENT}
        )
target_link_libraries(test_arq_client hpsocket)
target_include_directories(test_arq_client PRIVATE test/include)

add_executable(test_server_4c
        ${TEST_HELPER_CPP}
        ${TEST_HELPER_H}
        ${HTTP_SERVER_4C}
        )
target_link_libraries(test_server_4c hpsocket)
target_include_directories(test_server_4c PRIVATE test/include)

add_executable(test_udp_node
        ${TEST_HELPER_CPP}
        ${TEST_HELPER_H}
        ${UDP_NODE}
        )
target_link_libraries(test_udp_node hpsocket)
target_include_directories(test_udp_node PRIVATE test/include)



set(HTTP_STREAM_MJPEG test/httpServer/HttpStreamMJPEG.cpp
        test/httpServer/MJPGSender.cpp
        test/httpServer/MJPGSender.h)
aux_source_directory(test/httpServer/Http/ HTTP_SERVER_WRAP_HTTP_DIR)
aux_source_directory(test/httpServer/Http/rax/ HTTP_SERVER_WRAP_HTTP_RAX_DIR)

find_package(OpenCV CONFIG REQUIRED)
add_executable(test_http_stream_mjpeg
        ${TEST_HELPER_CPP}
        ${TEST_HELPER_H}
        ${HTTP_STREAM_MJPEG}
        ${HTTP_SERVER_WRAP_HTTP_DIR}
        ${HTTP_SERVER_WRAP_HTTP_RAX_DIR}
        )
target_link_libraries(test_http_stream_mjpeg PRIVATE hpsocket )
target_link_libraries(test_http_stream_mjpeg PRIVATE quirc  opencv_imgcodecs libprotobuf)
target_include_directories(test_http_stream_mjpeg PRIVATE test/include)
